class Solution {
public:
    int maxProduct(vector<int>& nums) {
        int n=nums.size();
        vector<int>f(n+1);
        auto g=f;
        vector<int>dp(n+1);
        f[0]=g[0]=1;
        int ret=-0x3f3f3f3f;
        for(int i=1;i<=n;i++)
        {
            int x=nums[i-1];int y=f[i-1]*nums[i-1];
            int z=g[i-1]*nums[i-1];
            f[i]=max(x,max(y,z));
            g[i]=min(x,min(y,z));
            ret=max(ret,f[i]);
        }
        return ret;

        
    }
};
